/*
 * TuringGraph.h
 *
 *  Created on: Jun 16, 2011
 *      Author: mariano
 */

#include "StateAction.h"

#ifndef TURINGGRAPH_H_
#define TURINGGRAPH_H_

class StateAction;

#include <list>
#include <vector>
#include <string>
#include <map>
using std::vector;
using std::map;
using std::string;
using std::list;

#define EMPTY_SPACE -1

class TuringMachine {

public:

	class Arc;



	class State {

	private:

		string name;
		map<int, Arc *> ArcMap;

	public:

		State(string name) :
			name(name) {
		}

		string getName() {
			return this->name;
		}

		Arc * getArc(int input) {
			return this->ArcMap[input];
		}

		void addAction(State * to, int input, StateAction * action) {
			this->ArcMap[input] = new Arc(to, action);
		}

		bool isNamed(char * namecmp){
			return name.compare(namecmp);
		}

	};

	

	class Arc {
	
	private:

		State * next;
		StateAction * action;
	public:
		
		Arc(State * nextState, StateAction * actionEx){
			next=nextState;
			action=actionEx;
		}
		
		
		State * getNext() {
			return next;
		}

		StateAction * getAction(){
			return action;
		}

	};


	int tapeIndex;	

	// Members of the Machine
	list<State *> states;
	State * actualState;

public:
	TuringMachine(char * initial);
	vector<int>* process(const vector<int>* finiteTape);
	bool nextStep(map<int, int> * tape);
	void addState(char * name);
	void addStateAction(char * from, char * to, int input, StateAction * action);

	bool hasState(string name);

	//debuging	
	string toString();
private:

	
	State * getState(string name);
	list<State *>& getStateList();
};

#endif /* TURINGGRAPH_H_ */
